package ymy.common;

import ymy.GeneralConfig;

public class Area {

    private int areaId;
    private int type;
    private Coordinate centralPosition;
    private double areaRadius;

    public Area() { }

    public int getAreaId() {
        return areaId;
    }

    public void setAreaId(int areaId) {
        this.areaId = areaId;
    }

    public Coordinate getCentralPosition() {
        return centralPosition;
    }

    public void setCentralPosition(Coordinate centralPosition) {
        this.centralPosition = centralPosition;
    }

    public double getAreaRadius() {
        return areaRadius;
    }

    public void setAreaRadius(double areaRadius) {
        this.areaRadius = areaRadius;
    }

    public int getType() {
        return type;
    }

    public void setType(int type) {
        this.type = type;
    }

    public boolean inArea(Coordinate c) {
        return this.inArea(c.getX(), c.getY());
    }

    public boolean inArea(double x, double y) {
        double tx = this.centralPosition.getX();
        double ty = this.centralPosition.getY();
        double val = (x - tx) * (x - tx) + (y - ty) * (y - ty);
        double target = (this.areaRadius * this.areaRadius) * GeneralConfig.CORRECTION_FACTOR;

        return val <= target;
    }

    @Override
    public boolean equals(Object o) {
        if (o == null)
            return false;
        if (o == this)
            return true;
        if (getClass() != o.getClass())
            return false;

        Area a = (Area)o;
        return this.areaId == a.areaId && this.centralPosition.equals(a.centralPosition);
    }

    @Override
    public String toString() {
        String str = "[";
        str += "ID = " + this.areaId;
        str += " || Center = " + this.centralPosition;
        str += " || Raduis = " + this.areaRadius;
        str += "]";
        return str;
    }
}
